define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'visiting_materials/index' + location.search,
                    add_url: 'visiting_materials/add',
                    edit_url: 'visiting_materials/edit',
                    del_url: 'visiting_materials/del',
                    multi_url: 'visiting_materials/multi',
                    import_url: 'visiting_materials/import',
                    table: 'visiting_materials',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'gender', title: __('Gender')},
                        {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'id_card', title: __('Id_card'), operate: 'LIKE'},
                        {field: 'return_permit', title: __('Return_permit'), operate: 'LIKE'},
                        {field: 'hk_address', title: __('Hk_address'), operate: 'LIKE'},
                        {field: 'nd_address', title: __('Nd_address'), operate: 'LIKE'},
                        {field: 'hk_mobile', title: __('Hk_mobile'), operate: 'LIKE'},
                        {field: 'nd_mobile', title: __('Nd_mobile'), operate: 'LIKE'},
                        {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'fm_mobile', title: __('Fm_mobile'), operate: 'LIKE'},
                        {field: 'native_place', title: __('Native_place'), operate: 'LIKE'},
                        {field: 'education', title: __('Education'), operate: 'LIKE'},
                        {field: 'cognitive_approach', title: __('Cognitive_approach'), operate: 'LIKE'},
                        {field: 'is_voter', title: __('Is_voter'), searchList: {"1":__('Is_voter 1'),"2":__('Is_voter 2')}, formatter: Table.api.formatter.normal},
                        {field: 'trade_union', title: __('Trade_union'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime')},
                        {field: 'updatetime', title: __('Updatetime')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});